package org.algorithm.YaYa.链表;

import org.algorithm.biubiu.wheel_1.common.ListNode;

import java.util.LinkedList;

/**
 * @Date 2022/2/18
 * @Link {https://leetcode-cn.com/problems/aMhZSa/}
 */
public class 回文链表 {

    public static void main(String[] args){
        ListNode node = ListNode.build(1,2,3,3,2,1);
        boolean b = isPalindrome(node);
        System.out.println(b);

    }

    public static boolean isPalindrome(ListNode head){
        LinkedList<Integer> list = new LinkedList<>();
        while(head!=null){
            list.add(head.val);
            head=head.next;
        }
        if(list.size()<2) return true;
        while(list.getFirst()==list.getLast()){
            list.removeFirst();
            list.removeLast();
            if(list.size()<2) return true;
        }
        return false;
    }
}
